package blockqueue_250225;

import java.util.concurrent.LinkedBlockingQueue;

public class LinkedBlockingQueueDemo {

    public static void main(String[] args) {
        LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue(5);

        new Thread(() -> {
           for (int i = 0; i < 10; i++) {
               try {
                   queue.put(i);
//                   queue.offer(i)
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        }).start();

        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                try {
                    Integer take = queue.take();
                    System.out.println(take);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }).start();
    }
}
